# -*-coding:utf-8-*-
# -*-coding:utf-8-*-

import re
from LAC import LAC
from ddparser import DDParser
import pkuseg

ddp = DDParser()
pkuseg = pkuseg.pkuseg()
lac = LAC()


def read_txt(path):
    with open(path, 'r', encoding='utf-8') as f:
        sents = []
        for sent in f.readlines():
            sent = sent.strip()
            sent = re.split(r"[。；：，！？]", sent)
            sents.append(sent[0])
    print(sents)
    return sents

def cut_sent(sent):
    #分词 返回fenci_pos_res,ddpres
    custom_dict = r'C:\Users\86130\Desktop\试试就逝世\diming_custom.txt'
    lac.load_customization(custom_dict, sep=None)
    pkures = pkuseg.cut(sent)
    lacres = lac.run(pkures)
    fenci_res = []
    pos_res = []
    for i in range(len(lacres)):
        for j in range(len(lacres[i][0])):
            fenci_res.append(lacres[i][0][j])
            pos_res.append(lacres[i][1][j])
    ddpres = ddp.parse_seg([fenci_res])
    return fenci_res, pos_res, ddpres

def read_hed(info_lst, hed_word):
    # 找头
    for i in range(len(info_lst)):
        if info_lst[i]['hed_word'] == hed_word:
            return info_lst[i]
    return {}

def read_word(info_lst, word_lst):
    # 找关键字
    for i in range(len(info_lst)):
        if info_lst[i]['word'] in word_lst:
            return info_lst[i]
    return {}

def read_pos(info_lst, pos_lst):
    # 找关键词性的relation
    for i in range(len(info_lst)):
        if info_lst[i]['pos'] in pos_lst:
            return info_lst[i]
    return {}



if __name__ == '__main__':
    path = 'data/test_you.txt'
    sentences = read_txt(path)